
$(document).ready(function () {

    $('#login_btn').click(function () {
        $('#loginForm').submit();
    });


    $("#loginForm").validate({
        rules: {
            username: {required: true},
            password: {required: true}
        },
        messages: {
            username: {
                required: "用户名不能为空"
            },
            password: {
                required: "密码不能为空"
            }
        },
        invalidHandler: function (form, validator) {
            if ($.fn.effect) {
                $("#mws-login").effect("shake", {distance: 6, times: 2}, 35);
            }
        },
        submitHandler: function (from) {
            // var a = $("#loginForm").serialize();
            // alert(a)
            $.ajax({
                type: "post",
                url: '/index.php?m=Admin&c=User&a=login',
                data: $("#loginForm").serialize(), // 要提交的表单
                dataType: 'json',
                success: function (data) {
                    if (data == '200') {
                        window.location.href = '/index.php?m=Admin&c=Sort&a=add';
                    } else {
                        layer.alert('用户不存在', {icon: 5});
                    }
                }
            });
        }
    });

    $.fn.placeholder && $('[placeholder]').placeholder();
});
